#!/bin/bash
# 安装systemd服务脚本

# 确保以root权限运行
if [ "$EUID" -ne 0 ]; then
  echo "请以root权限运行此脚本"
  exit 1
fi

echo "开始安装系统服务..."

# 创建日志目录
mkdir -p /var/log/gunicorn
chown root:root /var/log/gunicorn

# 拷贝服务文件到systemd目录
cp deploy_systemd.service /etc/systemd/system/project.service
cp deploy_celery.service /etc/systemd/system/project_celery.service

# 重新加载systemd配置
systemctl daemon-reload

# 启用服务
systemctl enable project.service
systemctl enable project_celery.service

# 启动服务
systemctl start project.service
systemctl start project_celery.service

# 检查服务状态
echo "Gunicorn服务状态:"
systemctl status project.service --no-pager

echo "Celery服务状态:"
systemctl status project_celery.service --no-pager

echo "服务安装完成！"
echo "您可以使用以下命令管理服务:"
echo "  启动: systemctl start project.service"
echo "  停止: systemctl stop project.service"
echo "  重启: systemctl restart project.service"
echo "  状态: systemctl status project.service"
echo "  日志: journalctl -u project.service" 